package ui;

import hxd.Pixels.Flags;
import tree.LeafCmd;
import h2d.domkit.Style;
import tree.LeafKind;
import hxd.Window;
import h2d.Flow;
import tree.Tress;


class ViewTress<T:Flow> extends Tress{
    private var m_center : Flow;
    private var m_view : T;
    private var m_isInit : Bool;
	private var m_type : Class<T>;
    private var m_style : Style;
    
    public function new(t:Class<T>) {
        super();
		m_type = t;
    
    }
    private function Init() {
        if(m_isInit){
            return;
        }
        m_isInit = true;
        
        m_center = new Flow(Main.GetInstance().UIRoot);
        m_center.horizontalAlign = m_center.verticalAlign = Middle;
		m_view = Type.createInstance(m_type, [m_center]);
		m_style.addObject(m_view);
        m_view.maxHeight = m_view.minHeight = Main.Height;
        m_view.maxWidth = m_view.minWidth = Main.Width;
    }



	public override function OnEnter(last:LeafKind) {
        super.OnEnter(last);
		Init();
	}

    public override function OnUpdate(cmd:LeafCmd) {
        super.OnUpdate(cmd);
        m_style.sync();
    }

}